package android07.newtop.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

import java.util.ArrayList;
import java.util.List;

import android07.newtop.R;
import android07.newtop.model.ApiService;
import android07.newtop.model.bean.PictureDetail;
import android07.newtop.utils.GlideUtil;
import android07.newtop.view.pictureshow.CardAdapterHelper;


public class PictureShowAdapter extends RecyclerView.Adapter<PictureShowAdapter.ViewHolder> {
        private List<PictureDetail.ListBean> mList = new ArrayList<>();
        private CardAdapterHelper mCardAdapterHelper = new CardAdapterHelper();

        public PictureShowAdapter() {
        }

    public  void setData(List<PictureDetail.ListBean>  mList){
        this.mList = mList;
        notifyDataSetChanged();
    }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.picture_show_item, parent, false);
            mCardAdapterHelper.onCreateViewHolder(parent, itemView);
            return new ViewHolder(itemView);
        }

        @Override
        public void onBindViewHolder(final ViewHolder holder, final int position) {
            if(mList.get(position)==null)
                return;
            mCardAdapterHelper.onBindViewHolder(holder.itemView, position, getItemCount());
            GlideUtil.setImageUrl(ApiService.PICTURE_ROOT_LOADURL+mList.get(position).getSrc(),holder.mImageView);
            holder.mImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
//                    ToastUtils.show(holder.mImageView.getContext(), "" + position);
                }
            });
        }

        @Override
        public int getItemCount() {

            return mList.size();
        }

        public class ViewHolder extends RecyclerView.ViewHolder {
            public final ImageView mImageView;

            public ViewHolder(final View itemView) {
                super(itemView);
                mImageView = (ImageView) itemView.findViewById(R.id.imageView);
            }

        }

    }




